package com.huawei.controller;

import com.alibaba.fastjson.JSON;

import com.huawei.entity.Spfenlei;

import com.huawei.service.SpfenleiService;
import com.huawei.util.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName SpfenleiController
 * @Description TODO
 * @Author 快乐的大胖
 * @Date 2021/12/6 16:57
 */
@Controller
@RequestMapping("/Spfenlei")
public class SpfenleiController {


    @Resource
    SpfenleiService  spfenleiImpl;


    //查询
    @RequestMapping(value = "/chaxun", produces = "text/html;charset=UTF-8")
    @ResponseBody
    public  String selectAll(
            @RequestParam(value = "father", required = false) Integer father
    ){
        Map<String, Object> pars = new HashMap<String, Object>();
        pars.put("father",father);
        List<Spfenlei> list = spfenleiImpl.selectAll(pars);
        Result result = new Result(0, "查询成功", 0, list);
        return JSON.toJSONString(result);
    }

    //修改
    @RequestMapping(value = "update", produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String update(
          Spfenlei spfenlei
    ) {
        int i = spfenleiImpl.update(spfenlei);
        if (i == 1) {
            return "修改成功";
        } else {
            return "修改失败";

        }


    }

    //添加
    @RequestMapping(value = "insert", produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String insert(
            Spfenlei spfenlei
    ) {
        int i = spfenleiImpl.insert(spfenlei);
        if (i == 1) {
            return "添加成功";
        } else {
            return "添加失败";

        }


    }

    //删除
    @RequestMapping(value = "detele", produces = "text/html;charset=UTF-8")
    @ResponseBody
    public  String detele(
            @RequestParam ("id")  Integer id
    ){


        int i = spfenleiImpl.delete(id);

        if (i == 1) {
            return "删除成功";
        } else {
            return "删除失败";

        }

    }




}
